package com.hsq.end_of_period;

import java.util.Scanner;

public class P60_1 {
    public static void main(String[] args) {
        int a = 0;
        int b = 0;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入两个整数：");
        a = scanner.nextInt();
        b = scanner.nextInt();
//        Math.sqrt(9);
        Complex complex = new Complex(a, b);
        System.out.println("请输入两个整数：");
        a = scanner.nextInt();
        b = scanner.nextInt();
        Complex complex1 = new Complex(a, b);
        complex = complex.complexAdd(complex1);
        System.out.println(complex.toString());
    }
}

class Complex {
    int realPart;
    int imaginPart;
    public Complex() {
        realPart = 0;
        imaginPart = 0;
    }
    public Complex(int r, int i) {
        realPart = r;
        imaginPart = i;
    }

    public Complex complexAdd(Complex a) {
        a.realPart += this.realPart;
        a.imaginPart += this.imaginPart;
        return a;
    }

    @Override
    public String toString() {
        if (this.imaginPart == 0)
            return this.realPart + "";
        if (this.realPart == 0)
            return this.imaginPart + "i";
        return this.realPart + "+" + this.imaginPart + "i";
    }
}

